#include<bits/stdc++.h>
using namespace std;
int n,q,p;
int s[500005];
int ans1[500005],ans2[500005];
int query(int a)
{
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            int b=s[j]-1LL*a*s[i]%p;
            b%=p;
            b+=p;
            b%=p;
            int flag=0;
            for(int k=i;k<=j;k++)
            {
                if((1LL*s[k]*a%p+b)%p!=s[i+j-k])
                {
                    flag=1;
                    break;
                }
            }
            if(flag)
            {
                continue;
            }
            ans1[a]++;
            ans2[b]++;
        }
    }
}
int main()
{
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    cin>>n>>q>>p;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    for(int i=0;i<p;i++)
    {
        query(i);
    }
    int op,x;
    for(int i=1;i<=q;i++)
    {
        cin>>op>>x;
        if(op==1)
        {
            cout<<ans1[x]<<endl;
        }
        else
        {
            cout<<ans2[x]<<endl;
        }
    }
    return 0;
}
